package com.model.demo.designmodel.template.jdbc;

import javax.sql.DataSource;
import java.sql.ResultSet;
import java.util.List;

public class UserDao extends JdbdTemplate {

    public UserDao(DataSource dataSource) {
        super(dataSource);
    }

    public List<?> selectAll(){
        String sql = "select * from user";
        return super.excuteQuery(sql, new RowMapper<User>() {
            @Override
            public User mapRow(ResultSet rs, int rowNum) throws Exception {
                User user=new User();
                user.setAge(rs.getInt("age"));
                user.setPassword(rs.getString("password"));
                user.setUserName(rs.getString("username"));
                return user;
            }
        },null);
    }

}
